package com.chensf.studydemo.guide.animation

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chensf.studydemo.R
import kotlinx.android.synthetic.main.activity_main.*

class AnimationGuideActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        recyclerView.adapter = object : RecyclerView.Adapter<MyViewHolder>() {
            override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
                return MyViewHolder(
                    layoutInflater.inflate(
                        R.layout.view_simple_list_item,
                        parent, false
                    )
                )
            }

            override fun getItemCount(): Int {
                return resources.getStringArray(R.array.anim_guide_level_dir).size
            }

            override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
                (holder.itemView as TextView).text =
                    resources.getStringArray(R.array.anim_guide_level_dir)[position]
                holder.itemView.setOnClickListener {
                    when (position) {
                        0 -> startActivity(
                            Intent(
                                this@AnimationGuideActivity,
                                GridToPager::class.java
                            )
                        )
                        1 -> startActivity(
                            Intent(
                                this@AnimationGuideActivity,
                                ValueAnim1::class.java
                            )
                        )
                        2 -> startActivity(
                            Intent(
                                this@AnimationGuideActivity,
                                MotionDemo1::class.java
                            )
                        )
                        3 -> startActivity(
                            Intent(
                                this@AnimationGuideActivity,
                                KeyboardAnimDemo1::class.java
                            )
                        )
                        4 -> startActivity(
                            Intent(
                                this@AnimationGuideActivity,
                                LottieAnim::class.java
                            )
                        )
                        else
                        -> startActivity(
                            Intent(
                                this@AnimationGuideActivity,
                                SimpleTransitionActivity::class.java
                            )
                        )
                    }
                }
            }
        }
        recyclerView.layoutManager = LinearLayoutManager(this)
    }

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}